import pandas as pd
import numpy as np
import plotly.graph_objects as go
import geopandas as gpd
import seaborn as sn
from statistics import mean
import statsmodels.api as sm
from statsmodels.formula.api import ols
from sklearn.preprocessing import LabelEncoder
from statsmodels.graphics.factorplots import interaction_plot
import matplotlib.pyplot as plt
# leitura dos dados do Sistema de Subvenção Econômica ao Prêmio Rural
psrd = pd.read_excel('files/psrdadosabertos2016a2021excel.xlsx')
# Leitura dos dados do Censo
censo = pd.read_excel('files/Atlas 2013_municipal, estadual e Brasil.xlsx', sheet_name='MUN 91-00-10')
# Leitura dos dados dos Municípios
mun = pd.read_csv('files/5 - municipio.csv', sep=';')
# Leitura dos dados do El Niño e La Niña
el_ln = pd.read_excel('files/EN-LN.xlsx')
psrd.replace('-', np.NaN, inplace=True)
psrd['sinistro_t'] = psrd['EVENTO_PREPONDERANTE'].apply(lambda x: 0 if pd.isnull(x) else 1)
censo = censo[['ANO', 'Codmun7', 'ESPVIDA', 'T_ENV', 'T_ANALF18M', 'GINI', 'RDPC', 'THEIL', 'pesoRUR', 'pesotot', 'pesourb', 'I_ESCOLARIDADE', 'I_FREQ_PROP', 'IDHM', 'IDHM_E', 'IDHM_L', 'IDHM_R', 'CORTE9', 'PREN20', 'PREN20RICOS', 'PEA']]
censo = censo[censo['ANO'] == 2010]
el_ln['SeasonP'] = el_ln['Season'].apply(lambda x: x.split('-')[0])
el_ln['SeasonP'] = el_ln['SeasonP'].astype(int)
el_ln['SeasonS'] = el_ln['Season'].apply(lambda x: x.split('-')[1])
el_ln['SeasonS'] = el_ln['SeasonS'].astype(int)
el_ln = el_ln[['Season','SeasonP','SeasonS','JFM','AMJ','JAS', 'OND', 'ENSO Type']]
psrd_t = pd.merge(psrd, mun, left_on=['NM_MUNICIPIO_PROPRIEDADE', 'SG_UF_PROPRIEDADE'], right_on=['nome_municipio', 'sigla_uf'])
def trat_season(ano):
season = el_ln.loc[el_ln['SeasonP'].isin([int(ano)])]
return season.iloc[0]['ENSO Type']
psrd_t['Season'] = psrd_t['ANO_APOLICE'].apply(lambda x: trat_season(x))
psrd_t['Season-1'] = psrd_t['ANO_APOLICE'].apply(lambda x: trat_season(x-1))
psrd.groupby(['NM_CULTURA_GLOBAL'])['NR_PROPOSTA'].count().sort_values(ascending=False)
NM_CULTURA_GLOBAL
Soja 318075
Milho 2ª safra 124645
Trigo 53333
Uva 52558
Milho 1ª safra 29814
...
Girassol 4
Ervilha 4
Centeio 3
Pastagem 2
Cacau 2
Name: NR_PROPOSTA, Length: 65, dtype: int64
100 * psrd.groupby(['NM_CULTURA_GLOBAL'])['NR_PROPOSTA'].count().sort_values(ascending=False) / sum(psrd.groupby(['NM_CULTURA_GLOBAL'])['NR_PROPOSTA'].count())
NM_CULTURA_GLOBAL
Soja 45.525459
Milho 2ª safra 17.840198
Trigo 7.633449
Uva 7.522525
Milho 1ª safra 4.267220
...
Girassol 0.000573
Ervilha 0.000573
Centeio 0.000429
Pastagem 0.000286
Cacau 0.000286
Name: NR_PROPOSTA, Length: 65, dtype: float64
psrd.groupby(by=['NM_CLASSIF_PRODUTO'])['NR_PROPOSTA'].count().sort_values(ascending=False)
NM_CLASSIF_PRODUTO PRODUTIVIDADE 380001 CUSTEIO 316441 PECUÁRIO 1665 FLORESTAS 492 RECEITA 76 Name: NR_PROPOSTA, dtype: int64
# Filtro de Soja e Produtividade
psrd = psrd[psrd['NM_CULTURA_GLOBAL'] == 'Soja']
psrd = psrd[psrd['NM_CLASSIF_PRODUTO'] == 'PRODUTIVIDADE']
len(psrd)
174625
temp_psrd = psrd.groupby(['ANO_APOLICE'])['NR_PROPOSTA'].count()
temp_psrd = temp_psrd.reset_index()
temp_psrd
| ANO_APOLICE | NR_PROPOSTA | |
|---|---|---|
| 0 | 2016 | 20609 |
| 1 | 2017 | 19455 |
| 2 | 2018 | 14890 |
| 3 | 2019 | 26031 |
| 4 | 2020 | 46120 |
| 5 | 2021 | 47520 |
psr_sin = psrd[~psrd['EVENTO_PREPONDERANTE'].isna()]
temp_psr = psr_sin.groupby(['ANO_APOLICE'])['NR_PROPOSTA'].count()
temp_psr = temp_psr.reset_index()
temp_psr
| ANO_APOLICE | NR_PROPOSTA | |
|---|---|---|
| 0 | 2016 | 477 |
| 1 | 2017 | 902 |
| 2 | 2018 | 3982 |
| 3 | 2019 | 4346 |
| 4 | 2020 | 4148 |
| 5 | 2021 | 4245 |
# Seguradoras que mais indenizaram
temp_psr = psrd.groupby(['NM_RAZAO_SOCIAL'])[['VL_LIMITE_GARANTIA', 'VL_SUBVENCAO_FEDERAL','VALOR_INDENIZAÇÃO']].sum()
temp_psr = temp_psr.reset_index().sort_values(by='VALOR_INDENIZAÇÃO',ascending=False)
temp_psr
| NM_RAZAO_SOCIAL | VL_LIMITE_GARANTIA | VL_SUBVENCAO_FEDERAL | VALOR_INDENIZAÇÃO | |
|---|---|---|---|---|
| 5 | Mapfre Seguros Gerais S.A. | 2.242494e+09 | 3.983228e+07 | 2.764966e+08 |
| 9 | Sancor Seguros do Brasil S.A. | 4.703216e+09 | 1.164356e+08 | 2.668207e+08 |
| 4 | FairFax Brasil Seguros Corporativos S/A | 6.889175e+09 | 1.203216e+08 | 2.162739e+08 |
| 3 | Essor Seguros S.A. | 7.069353e+09 | 1.260808e+08 | 1.491059e+08 |
| 12 | Tokio Marine Seguradora S.A. | 3.782916e+09 | 5.600107e+07 | 1.145307e+08 |
| 11 | Swiss Re Corporate Solutions Brasil S.A. | 6.463082e+09 | 1.242634e+08 | 8.926691e+07 |
| 0 | Allianz Seguros S.A | 5.349305e+09 | 8.760429e+07 | 7.431483e+07 |
| 13 | Too Seguros S.A. | 3.471791e+09 | 5.530765e+07 | 6.322046e+07 |
| 8 | Porto Seguro Companhia de Seguros Gerais | 6.968918e+08 | 8.029449e+06 | 3.731312e+07 |
| 10 | Sompo Seguros S/A | 1.121588e+09 | 1.496472e+07 | 3.552130e+07 |
| 1 | Companhia Excelsior de Seguros | 6.839535e+08 | 1.212455e+07 | 1.323676e+07 |
| 2 | EZZE Seguros S.A. | 1.739877e+08 | 2.055624e+06 | 4.025262e+05 |
| 6 | Newe Seguros S.A | 1.594804e+07 | 4.955323e+05 | 0.000000e+00 |
| 7 | Nobre Seguradora do Brasil S.A | 1.052423e+08 | 6.731453e+05 | 0.000000e+00 |
temp_psr_sin = psrd.groupby(['ANO_APOLICE'])['EVENTO_PREPONDERANTE'].count()
temp_psr_sin = temp_psr_sin.reset_index()
temp_psr = psrd.groupby(['ANO_APOLICE'])['NR_PROPOSTA'].count()
temp_psrd = temp_psrd.reset_index()
fig = go.Figure()
fig.add_trace(go.Scatter(x = temp_psr_sin['ANO_APOLICE'], y = temp_psr_sin['EVENTO_PREPONDERANTE'], name = 'Sinistro'))
fig.add_trace(go.Scatter(x = temp_psrd['ANO_APOLICE'], y = temp_psrd['NR_PROPOSTA'], name = 'Apólices'))
fig.update_layout(title='Quantidade de Apólices x Quantidade de Sinistros',
xaxis_title='Ano Apólice',
yaxis_title='Apólices',
plot_bgcolor = 'white',
font = {'family': 'Arial','size': 16,'color': 'black'})
fig.update_xaxes( showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1, linecolor='black')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1,linecolor='black')
fig.show()
temp_psrd = psrd.groupby(['ANO_APOLICE'])['VL_SUBVENCAO_FEDERAL'].sum()
temp_psrd = temp_psrd.reset_index()
temp_psr = psrd.groupby(['ANO_APOLICE'])['VALOR_INDENIZAÇÃO'].sum()
temp_psr = temp_psr.reset_index()
fig = go.Figure()
fig.add_trace(go.Scatter(x = temp_psrd['ANO_APOLICE'], y = temp_psrd['VL_SUBVENCAO_FEDERAL'], name = 'Subvenção Federal'))
fig.add_trace(go.Scatter(x = temp_psr['ANO_APOLICE'], y = temp_psr['VALOR_INDENIZAÇÃO'], name = 'Indenizações'))
fig.update_layout(title='Subvenção Federal',
xaxis_title='Ano',
yaxis_title='Apólices',
plot_bgcolor = 'white',
font = {'family': 'Arial','size': 16,'color': 'black'})
fig.update_xaxes( showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1, linecolor='black')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1,linecolor='black')
fig.show()
temp_psr = psrd.groupby(['EVENTO_PREPONDERANTE'])['NR_PROPOSTA'].count()
temp_psr = temp_psr.reset_index()
fig = go.Figure()
fig.add_trace(go.Bar(x = temp_psr['EVENTO_PREPONDERANTE'], y = temp_psr['NR_PROPOSTA'], name = 'Valor'))
fig.update_layout(title='Quantidade de Apólices por Motivo de Sinistralidade',
xaxis_title='Evento',
yaxis_title='Apólices',
plot_bgcolor = 'white',
font = {'family': 'Arial','size': 16,'color': 'black'},
barmode='group')
fig.update_xaxes( showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1, linecolor='black')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1,linecolor='black')
fig.show()
temp_psr = psrd.groupby(['NM_RAZAO_SOCIAL'])['NR_PROPOSTA'].count()
temp_psr = temp_psr.reset_index()
fig = go.Figure()
fig.add_trace(go.Bar(x = temp_psr['NM_RAZAO_SOCIAL'], y = temp_psr['NR_PROPOSTA'], name = 'Valor'))
fig.update_layout(title='Quantidade de Apólices por Seguradora',
xaxis_title='Apólices',
yaxis_title='Seguradora',
plot_bgcolor = 'white',
font = {'family': 'Arial','size': 16,'color': 'black'},
barmode='group')
fig.update_xaxes( showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1, linecolor='black')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1,linecolor='black')
fig.show()
psrd_t_sin = psrd_t[~psrd_t['EVENTO_PREPONDERANTE'].isna()]
temp_psr = psrd_t_sin.groupby(['Season'])['NR_PROPOSTA'].count()
temp_psr = temp_psr.reset_index()
psrd_t_nsin = psrd_t[psrd_t['EVENTO_PREPONDERANTE'].isna()]
temp_psr_nsin = psrd_t_nsin.groupby(['Season'])['NR_PROPOSTA'].count()
temp_psr_nsin = temp_psr_nsin.reset_index()
fig = go.Figure(data=[
go.Bar(name='Com sinistro', x=temp_psr['Season'], y=temp_psr['NR_PROPOSTA']),
go.Bar(name='Sem Sinistro', x=temp_psr_nsin['Season'], y=temp_psr_nsin['NR_PROPOSTA'])
])
fig.update_layout(title='Apólices por Evento Lã Nina e El Ninõ no Ano Corrente',
xaxis_title='Apólices',
yaxis_title='Evento',
plot_bgcolor = 'white',
font = {'family': 'Arial','size': 16,'color': 'black'},
barmode='group')
fig.update_xaxes( showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1, linecolor='black')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1,linecolor='black')
fig.show()
psrd_t_sin = psrd_t[~psrd_t['EVENTO_PREPONDERANTE'].isna()]
temp_psr = psrd_t_sin.groupby(['Season-1'])['NR_PROPOSTA'].count()
temp_psr = temp_psr.reset_index()
psrd_t_nsin = psrd_t[psrd_t['EVENTO_PREPONDERANTE'].isna()]
temp_psr_nsin = psrd_t_nsin.groupby(['Season-1'])['NR_PROPOSTA'].count()
temp_psr_nsin = temp_psr_nsin.reset_index()
fig = go.Figure(data=[
go.Bar(name='Com sinistro', x=temp_psr['Season-1'], y=temp_psr['NR_PROPOSTA']),
go.Bar(name='Sem Sinistro', x=temp_psr_nsin['Season-1'], y=temp_psr_nsin['NR_PROPOSTA'])
])
fig.update_layout(title='Apólices por Evento Lã Nina e El Ninõ no Ano Anterior',
xaxis_title='Apólices',
yaxis_title='Evento',
plot_bgcolor = 'white',
font = {'family': 'Arial','size': 16,'color': 'black'},
barmode='group')
fig.update_xaxes( showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1, linecolor='black')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray',showline=True, linewidth=1,linecolor='black')
fig.show()
psrd_taxa = psrd_t.groupby(by=['NM_MUNICIPIO_PROPRIEDADE', 'id_municipio'])[['NR_PROPOSTA', 'EVENTO_PREPONDERANTE', 'VL_LIMITE_GARANTIA', 'VL_SUBVENCAO_FEDERAL']].count().sort_values(by=['NR_PROPOSTA'],ascending=False)
psrd_taxa['DIFF'] = (psrd_taxa['EVENTO_PREPONDERANTE']/psrd_taxa['NR_PROPOSTA'])*100
psrd_taxa.reset_index(inplace=True)
psrd_taxa.rename(columns={'id_municipio': 'id'}, inplace=True)
psrd_taxa = pd.merge(psrd_taxa, censo, left_on=['id'], right_on=['Codmun7'])
psrd_taxa = psrd_taxa.drop(columns=['ANO', 'Codmun7', 'NM_MUNICIPIO_PROPRIEDADE', 'SG_UF_PROPRIEDADE'], errors='ignore')
correlation = psrd_taxa.corr()
plot = sn.heatmap(correlation)
plot
<Axes: >
resultP = pd.merge(psrd,el_ln,left_on=['ANO_APOLICE'],right_on=['SeasonP'])
tamanho_desejado = 100000
df_reduzido = resultP.sample(n=tamanho_desejado, random_state=42)
df_reduzido
| NM_RAZAO_SOCIAL | CD_PROCESSO_SUSEP | NR_PROPOSTA | ID_PROPOSTA | DT_PROPOSTA | DT_INICIO_VIGENCIA | DT_FIM_VIGENCIA | NM_SEGURADO | NR_DOCUMENTO_SEGURADO | NM_MUNICIPIO_PROPRIEDADE | ... | EVENTO_PREPONDERANTE | sinistro_t | Season | SeasonP | SeasonS | JFM | AMJ | JAS | OND | ENSO Type | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 140411 | Essor Seguros S.A. | 15414004513201247 | 118111164578031 | 1200924 | 2020-08-20 | 2020-08-20 | 2021-05-31 00:00:00 | GERALDO KWIATKOWSKI | ***27529915 | Itaiópolis | ... | NaN | 0 | 2020-2021 | 2020 | 2021 | -0.9 | -0.5 | -0.6 | -1.3 | ML |
| 24647 | Mapfre Seguros Gerais S.A. | 15414900586201342 | 5029668099466 | 1360380 | 2021-05-24 | 2021-05-24 | 2022-03-30 00:00:00 | ADEMIR WISOM MUSSKOPF | ***10305934 | Glória de Dourados | ... | SECA | 1 | 2021-2022 | 2021 | 2022 | -0.9 | -1.0 | -0.5 | -1.0 | ML |
| 1689 | Allianz Seguros S.A | 15414002759200717 | 116885939 | 1388553 | 2021-07-09 | 2021-10-01 | 2022-04-19 00:00:00 | SERGIO FRANZOLI | ***63017803 | Birigüi | ... | NaN | 0 | 2021-2022 | 2021 | 2022 | -0.9 | -1.0 | -0.5 | -1.0 | ML |
| 113701 | FairFax Brasil Seguros Corporativos S/A | 15414004195201052 | 10000116410000293481 | 1080132 | 2019-09-25 | 2019-09-25 | 2020-03-29 00:00:00 | JUCINEI ANTONIO SARTORETTO | ***31536900 | Tiradentes | ... | NaN | 0 | 2019-2020 | 2019 | 2020 | 0.5 | -0.1 | 0.1 | 0.5 | NaN |
| 167836 | Tokio Marine Seguradora S.A. | 15414900116201621 | 3361771 | 1266151 | 2020-10-30 | 2020-10-30 | 2021-05-30 00:00:00 | ADINEI MAGALSKI | ***57800910 | Laranjeiras do Sul | ... | NaN | 0 | 2020-2021 | 2020 | 2021 | -0.9 | -0.5 | -0.6 | -1.3 | ML |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 75116 | FairFax Brasil Seguros Corporativos S/A | 15414004195201052 | 10000116410000267575 | 867981 | 2017-08-01 | 2017-10-11 | 2018-03-29 00:00:00 | WANDERLEI AUGUSTO CAPPELLESSO | ***58725915 | Palmas | ... | NaN | 0 | 2017-2018 | 2017 | 2018 | -0.9 | -0.2 | -0.1 | -0.8 | WL |
| 119386 | Swiss Re Corporate Solutions Brasil S.A. | 15414002154200564 | 02011136348 | 1023993 | 2019-06-12 | 2019-06-12 | 2020-03-09 00:00:00 | ARY PREBIANCA POLESE | ***07372972 | Coronel Vivida | ... | NaN | 0 | 2019-2020 | 2019 | 2020 | 0.5 | -0.1 | 0.1 | 0.5 | NaN |
| 127650 | Too Seguros S.A. | 15414900961201869 | 5346 | 1057241 | 2019-08-26 | 2019-11-07 | 2020-05-05 00:00:00 | PATRICIA KERBER VIERA | ***28581059 | São Luiz Gonzaga | ... | SECA | 1 | 2019-2020 | 2019 | 2020 | 0.5 | -0.1 | 0.1 | 0.5 | NaN |
| 8094 | Essor Seguros S.A. | 15414004513201247 | 118112125197408 | 1391094 | 2021-06-22 | 2021-07-01 | 2022-05-31 00:00:00 | VALMIR MOLSSATO | ***19054004 | Ernestina | ... | NaN | 0 | 2021-2022 | 2021 | 2022 | -0.9 | -1.0 | -0.5 | -1.0 | ML |
| 8974 | Essor Seguros S.A. | 15414004513201247 | 118112125259366 | 1407953 | 2021-07-13 | 2021-07-13 | 2022-05-31 00:00:00 | EMERSON DIAS GOMES | ***14003962 | Nova Andradina | ... | NaN | 0 | 2021-2022 | 2021 | 2022 | -0.9 | -1.0 | -0.5 | -1.0 | ML |
100000 rows × 47 columns
d_melt = pd.melt(df_reduzido, id_vars=['sinistro_t'], value_vars=['JFM','AMJ','JAS', 'OND'])
label_encoder = LabelEncoder()
d_melt['variable_num']=label_encoder.fit_transform(d_melt['variable'])
model = ols('value~C(sinistro_t)+C(variable)+C(sinistro_t):C(variable)', data=d_melt).fit()
anova_table = sm.stats.anova_lm(model, typ=3)
anova_table
| sum_sq | df | F | PR(>F) | |
|---|---|---|---|---|
| Intercept | 12552.799942 | 1.0 | 40532.242470 | 0.000000e+00 |
| C(sinistro_t) | 106.869686 | 1.0 | 345.075842 | 5.394571e-77 |
| C(variable) | 6125.553414 | 3.0 | 6593.015566 | 0.000000e+00 |
| C(sinistro_t):C(variable) | 541.938667 | 3.0 | 583.295880 | 0.000000e+00 |
| Residual | 123877.171567 | 399992.0 | NaN | NaN |
d_melt['sinistro']=label_encoder.fit_transform(d_melt['sinistro_t'])
fig = interaction_plot(x=d_melt['sinistro'], trace=d_melt['variable'], response=d_melt['value'])
plt.legend(bbox_to_anchor=(1.02, 1), loc='upper left', borderaxespad=0)
plt.show()
resultS = pd.merge(psrd,el_ln,left_on=['ANO_APOLICE'],right_on=['SeasonS'])
tamanho_desejado = 100000
df_reduzido = resultS.sample(n=tamanho_desejado, random_state=42)
df_reduzido
| NM_RAZAO_SOCIAL | CD_PROCESSO_SUSEP | NR_PROPOSTA | ID_PROPOSTA | DT_PROPOSTA | DT_INICIO_VIGENCIA | DT_FIM_VIGENCIA | NM_SEGURADO | NR_DOCUMENTO_SEGURADO | NM_MUNICIPIO_PROPRIEDADE | ... | EVENTO_PREPONDERANTE | sinistro_t | Season | SeasonP | SeasonS | JFM | AMJ | JAS | OND | ENSO Type | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 140411 | Essor Seguros S.A. | 15414004513201247 | 118111164578031 | 1200924 | 2020-08-20 | 2020-08-20 | 2021-05-31 00:00:00 | GERALDO KWIATKOWSKI | ***27529915 | Itaiópolis | ... | NaN | 0 | 2019-2020 | 2019 | 2020 | 0.5 | -0.1 | 0.1 | 0.5 | NaN |
| 24647 | Mapfre Seguros Gerais S.A. | 15414900586201342 | 5029668099466 | 1360380 | 2021-05-24 | 2021-05-24 | 2022-03-30 00:00:00 | ADEMIR WISOM MUSSKOPF | ***10305934 | Glória de Dourados | ... | SECA | 1 | 2020-2021 | 2020 | 2021 | -0.9 | -0.5 | -0.6 | -1.3 | ML |
| 1689 | Allianz Seguros S.A | 15414002759200717 | 116885939 | 1388553 | 2021-07-09 | 2021-10-01 | 2022-04-19 00:00:00 | SERGIO FRANZOLI | ***63017803 | Birigüi | ... | NaN | 0 | 2020-2021 | 2020 | 2021 | -0.9 | -0.5 | -0.6 | -1.3 | ML |
| 113701 | FairFax Brasil Seguros Corporativos S/A | 15414004195201052 | 10000116410000293481 | 1080132 | 2019-09-25 | 2019-09-25 | 2020-03-29 00:00:00 | JUCINEI ANTONIO SARTORETTO | ***31536900 | Tiradentes | ... | NaN | 0 | 2018-2019 | 2018 | 2019 | 0.7 | 0.5 | 0.2 | 0.9 | WE |
| 167836 | Tokio Marine Seguradora S.A. | 15414900116201621 | 3361771 | 1266151 | 2020-10-30 | 2020-10-30 | 2021-05-30 00:00:00 | ADINEI MAGALSKI | ***57800910 | Laranjeiras do Sul | ... | NaN | 0 | 2019-2020 | 2019 | 2020 | 0.5 | -0.1 | 0.1 | 0.5 | NaN |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 75116 | FairFax Brasil Seguros Corporativos S/A | 15414004195201052 | 10000116410000267575 | 867981 | 2017-08-01 | 2017-10-11 | 2018-03-29 00:00:00 | WANDERLEI AUGUSTO CAPPELLESSO | ***58725915 | Palmas | ... | NaN | 0 | 2016-2017 | 2016 | 2017 | -0.2 | 0.3 | -0.5 | -0.7 | WL |
| 119386 | Swiss Re Corporate Solutions Brasil S.A. | 15414002154200564 | 02011136348 | 1023993 | 2019-06-12 | 2019-06-12 | 2020-03-09 00:00:00 | ARY PREBIANCA POLESE | ***07372972 | Coronel Vivida | ... | NaN | 0 | 2018-2019 | 2018 | 2019 | 0.7 | 0.5 | 0.2 | 0.9 | WE |
| 127650 | Too Seguros S.A. | 15414900961201869 | 5346 | 1057241 | 2019-08-26 | 2019-11-07 | 2020-05-05 00:00:00 | PATRICIA KERBER VIERA | ***28581059 | São Luiz Gonzaga | ... | SECA | 1 | 2018-2019 | 2018 | 2019 | 0.7 | 0.5 | 0.2 | 0.9 | WE |
| 8094 | Essor Seguros S.A. | 15414004513201247 | 118112125197408 | 1391094 | 2021-06-22 | 2021-07-01 | 2022-05-31 00:00:00 | VALMIR MOLSSATO | ***19054004 | Ernestina | ... | NaN | 0 | 2020-2021 | 2020 | 2021 | -0.9 | -0.5 | -0.6 | -1.3 | ML |
| 8974 | Essor Seguros S.A. | 15414004513201247 | 118112125259366 | 1407953 | 2021-07-13 | 2021-07-13 | 2022-05-31 00:00:00 | EMERSON DIAS GOMES | ***14003962 | Nova Andradina | ... | NaN | 0 | 2020-2021 | 2020 | 2021 | -0.9 | -0.5 | -0.6 | -1.3 | ML |
100000 rows × 47 columns
d_melt = pd.melt(df_reduzido, id_vars=['sinistro_t'], value_vars=['JFM','AMJ','JAS', 'OND'])
label_encoder = LabelEncoder()
d_melt['variable_num']=label_encoder.fit_transform(d_melt['variable'])
model = ols('value~C(sinistro_t)+C(variable)+C(sinistro_t):C(variable)', data=d_melt).fit()
anova_table = sm.stats.anova_lm(model, typ=3)
anova_table
| sum_sq | df | F | PR(>F) | |
|---|---|---|---|---|
| Intercept | 44.166436 | 1.0 | 55.688758 | 8.507299e-14 |
| C(sinistro_t) | 1.951266 | 1.0 | 2.460320 | 1.167558e-01 |
| C(variable) | 1674.415382 | 3.0 | 703.747927 | 0.000000e+00 |
| C(sinistro_t):C(variable) | 292.654490 | 3.0 | 123.001134 | 1.245359e-79 |
| Residual | 317231.370147 | 399992.0 | NaN | NaN |
d_melt['sinistro']=label_encoder.fit_transform(d_melt['sinistro_t'])
fig = interaction_plot(x=d_melt['sinistro'], trace=d_melt['variable'], response=d_melt['value'])
plt.legend(bbox_to_anchor=(1.02, 1), loc='upper left', borderaxespad=0)
plt.show()